<template>
  <van-popup
    class="popup long"
    v-model="show"
    position="bottom"
    :close-on-click-overlay="true"
  >
    <h3 class="title">
      请输入支付密码
    </h3>
    <!-- 密码输入框 -->
    <van-password-input
      :value="value"
      info="密码为 6 位数字"
      :focused="showKeyboard"
      @focus="showKeyboard = true"
    />
    <p class="forget">
      <a href="/">忘记密码</a>
    </p>
    <!-- 数字键盘 -->
    <van-number-keyboard
      :show="showKeyboard"
      @input="onInput"
      @delete="onDelete"
      @blur="showKeyboard = false"
    />
  </van-popup>
</template>

<script>
export default {
  props: {
    show: {
      type: Boolean,
      default: false
    }
  },
  data() {
    return {
      value: "",
      showKeyboard: true,
      errorInfo: ""
    };
  },
  methods: {
    onInput(key) {
      this.value = (this.value + key).slice(0, 6);
      if (this.value.length === 6) {
        this.errorInfo = "密码错误";
      } else {
        this.errorInfo = "";
      }
    },
    onDelete() {
      this.value = this.value.slice(0, this.value.length - 1);
    }
  }
};
</script>

<style lang="scss" scoped>
.forget {
  text-align: right;
  padding: 0 10px;
  a {
    color: #8ba4ca;
  }
}
</style>
